<?php
if(!interface_exists('XConfigLoader', false)){
	require(XFRAMEWORK_DIR.'/core/config/XConfigLoader.php');
}
class XXMLConfigLoader implements XConfigLoader{
	public function load($file){
		$xml = new DOMDocument();
		$xml->load($file);
		$project = $xml->getElementsByTagName('project')->item(0);
		$array = array();
		$this->_addNode($project, $array);
		return array(
			'project' => $array,
		);
	}
	
	private function _addNode($node, &$array){
		if($node && isset($node->attributes)){
			$attributes = $node->attributes;
			if($attributes){
				$i = 0;
				while($item = $attributes->item($i++)){
					$array[$item->name] = $item->value;
				}
			}			
		}
		if($node && isset($node->childNodes)){
			$children = $node->childNodes;
			if(!$children){
				return;
			}
			$length = $children->length;
			for($i = 0; $i < $length; $i++){
				$child = $children->item($i);
				if(preg_match('/^#/i', $child->nodeName)){
					continue;
				}
				$item = array();
				$this->_addNode($child, $item);
				$array[$child->nodeName][] = $item;
			}			
		}
	}
}
?>